q = input()
w = 0
if len(q) == 4:
    for r in range(0,4):
        for e in range(r + 1,5):
            o = int(q[r:e])
            u = 0
            for t in range(1,o + 1):
                if o % t == 0:
                    u = u + 1
            if u == 2:
                w = max(w,o)
print(w)